package com.dm0858.bianmin.mine.adapter;

import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.icu.text.UnicodeSetSpanner;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

import com.dm0858.bianmin.R;
import com.dm0858.bianmin.app.MyApp;
import com.dm0858.bianmin.mine.activity.BindPhoneActivity;
import com.dm0858.bianmin.mine.activity.MyFavoriteActivity;
import com.dm0858.bianmin.mine.activity.MyReleaseActivity;
import com.dm0858.bianmin.mine.activity.PostManageActivity;
import com.dm0858.bianmin.mine.base.BaseRecyclerViewAdapter;
import com.dm0858.bianmin.mine.base.BaseViewHolder;
import com.dm0858.bianmin.mine.bean.Item;
import com.dm0858.bianmin.mine.tools.DialogUtils;
import com.dm0858.bianmin.mine.tools.ToastUtils;
import com.dm0858.bianmin.ui.activity.AgreementActivity;
import com.dm0858.bianmin.ui.activity.Main2LayoutActivity;

import java.util.List;

public class MineRecyclerViewAdapter extends BaseRecyclerViewAdapter {

    private Context mContext;

    private List<Item> items;

    /**
     * 构造方法
     *
     * @param mContext
     * @param resource
     * @param data
     */
    public MineRecyclerViewAdapter(Context mContext, int resource, List data) {
        super(mContext, resource, data);
        this.mContext = mContext;
        if (data != null) this.items = data;
    }

    @Override
    protected void bindData(BaseViewHolder holder, int position) {
        Item item = items.get(position);
        holder
                .setImageResource(R.id.img_icon,item.getItemIcon())
                .setText(R.id.txt_itemName,item.getItemName())
                .setOnClickListener(R.id.item, view -> {
                    if (MyApp.userid.equals("")){
                        if (MyApp.openid.equals("")){
                            ToastUtils.showShort("您还未登录");

                        }else {
                            DialogUtils.showTipDialog(mContext, "绑定手机号", "您的账户需要绑定手机后才能使用此功能，是否需要绑定手机？", new DialogUtils.onClickListener() {
                                @Override
                                public void negativeClick() {

                                }

                                @Override
                                public void positiveClick() {
                                    Bundle b = new Bundle();
                                    b.putString("openid", MyApp.openid);
                                    Intent intent = new Intent(mContext, BindPhoneActivity.class);
                                    intent.putExtras(b);
                                    mContext.startActivity(intent);
                                }

                                @Override
                                public void cancelClick() {

                                }

                                @Override
                                public void onClick(DialogInterface dialogInterface, int i) {

                                }
                            });
                        }
                        return;
                    }
                    if (position == 0 || position == 1) mContext.startActivity(new Intent(mContext, AgreementActivity.class));
                    else if (position == 2) mContext.startActivity(new Intent(mContext, MyReleaseActivity.class));
                    else if (position == 3) mContext.startActivity(new Intent(mContext, PostManageActivity.class));
                    else if (position == 4) mContext.startActivity(new Intent(mContext, MyFavoriteActivity.class));
                });
    }

    @Override
    protected int getSize() {
        if (items == null) return 0;
        return items.size();
    }
}
